﻿using LogForParameter.Api.SwaggerHelp;
using LogForParameter.IServices;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.AI;
using ViewModel;
using ViewModels;

namespace LogForParameter.Api.Controllers
{
    [CustomRoute(CustomApiVersion.MyApiVersion.AI)]
    [ApiController]
    public class AIChatController : ControllerBase
    {
        private readonly ILogger<AIChatController> log;
        private readonly IChatClient chatClient;
        public AIChatController(ILogger<AIChatController> log, IChatClient chatClient)
        {
            this.log = log;
            this.chatClient = chatClient;
        }
        /// <summary>
        /// 聊天
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OutPut> chat(AIChatReq req)
        {
            OutPut res = Public.NewOP_Ok("");
            var resData = await chatClient.CompleteAsync($"{req.text}");
            res.ResultData.Add(resData);
            return res;
        }
        /// <summary>
        /// 聊天
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OutPut> chatStream(AIChatReq req)
        {
            OutPut res = Public.NewOP_Ok("");
            var reslist = chatClient.CompleteStreamingAsync($"{req.text}");
            await foreach (var resData in reslist)
            {
                res.ResultData.Add(resData);
            }
            return res;
        }
    }
}
